package org.mikhaylov.cp.service.command;

import java.io.Serializable;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.mikhaylov.cp.service.response.Response;

public abstract class ServiceCommand implements Serializable {

	private static final long serialVersionUID = -4812088101228617787L;
	protected Response response = new Response();
	
	protected String meta = null;
	
	public String getMeta() {
		return meta;
	}
	
	public Response execute (HttpServletRequest request,
			HttpServletResponse response) {
		
		if (checkParams(request)) {
			if (extractParams(request)) {
				process(request);
			}
		}

		return this.response;
	}
	
	protected abstract boolean checkParams(HttpServletRequest request);
	
	protected abstract boolean extractParams(HttpServletRequest request);
	
	protected abstract void process(HttpServletRequest request);
	
	@Override
	public final String toString() {
		return getClass().getSimpleName();
	}
	
}
